#include <gtest/gtest.h>
#include "../mqserver/mq_exchange.hpp"

mq_zxws::ExchangeManager::ptr emp;

class ExchangeTest: public testing::Environment
{
public:
    virtual void SetUp()override{
        emp = std::make_shared<mq_zxws::ExchangeManager>("./data/meta.db");
    }
    virtual void TearDown()override{
        // emp->clear();
    }
};

TEST(exchange_test, insert_test){
    
    std::unordered_map<std::string, std::string> mp = {{"k1","v1"}, {"k2","v2"}};
    std::unordered_map<std::string, std::string> m;
    emp->declareExchange("exchange1",mq_zxws::ExchangeType::DIRECT, true, false, m);
    // emp->declareExchange("exchange2",mq_zxws::ExchangeType::DIRECT, true, false, mp);
    // emp->declareExchange("exchange3",mq_zxws::ExchangeType::DIRECT, true, false, mp);
    // emp->declareExchange("exchange4",mq_zxws::ExchangeType::DIRECT, true, false, mp);
    ASSERT_EQ(emp->size(), 4);
}

// TEST(exchange_test, recovery_test){
//     auto it = emp->selectOne("exchange2");
//     ASSERT_EQ(emp->exists("exchange1"), false);
//     ASSERT_EQ(emp->exists("exchange2"), true);
//     ASSERT_EQ(emp->exists("exchange3"), true);
//     ASSERT_EQ(emp->exists("exchange4"), true);
// }


// TEST(exchange_test, select_test){
//     auto it = emp->selectOne("exchange1");
//     ASSERT_EQ(it->name, "exchange1");
//     ASSERT_EQ(it->type, mq_zxws::ExchangeType::DIRECT);
//     ASSERT_EQ(it->durable, true);
//     ASSERT_EQ(it->auto_delete, false);
//     ASSERT_EQ(it->getArgs(), std::string("k1=v1&k2=v2&"));
// }

// TEST(exchange_test, delete_test){
//     emp->deleteExchange("exchange1");
//     auto it = emp->selectOne("exchange1");
//     ASSERT_EQ(it.get(), nullptr);
//     ASSERT_EQ(emp->exists("exchange1"), false);
// }



int main(int argc, char*argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int res = RUN_ALL_TESTS();
    return 0;
}